//
//  XXBaseViewController.swift
//  XXSwiftDemo
//
//  Created by admin on 2022/4/14.
//

import UIKit

class XXViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

public extension UIViewController {

    func push(_ vc:UIViewController) {
        vc.hidesBottomBarWhenPushed = true
        self.navigationController?.pushViewController(vc, animated: true)
    }
    func pop() {
        self.navigationController?.popViewController(animated: true)
    }
    func present(_ vc:UIViewController) {
        vc.modalPresentationStyle = UIModalPresentationStyle.fullScreen
        self.present(vc, animated: true, completion: nil)
    }
    func dismiss() {
        self.dismiss(animated: true, completion: nil)
    }
    
    func perform(str:String,obj:Any?) {
        let selector:Selector = NSSelectorFromString(str)
        if (self.responds(to: selector)){
            self.perform(selector,with: obj)
        }
    }
    
    func currentViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
        if let nav = base as? UINavigationController {
            return currentViewController(base: nav.visibleViewController)
        }
        if let tab = base as? UITabBarController {
            return currentViewController(base: tab.selectedViewController)
        }
        if let presented = base?.presentedViewController {
            return currentViewController(base: presented)
        }
        return base
    }
    
    
}

